package com.heima.xxljob.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MyJob {

    @XxlJob("myjob-run")
    public void run(){
        //获取当前实例的索引
        int shardIndex = XxlJobHelper.getShardIndex();
        //获取所有实例的个数
        int shardTotal = XxlJobHelper.getShardTotal();

        log.info("当前实例的索引{},总实例的个数{}",shardIndex,shardTotal);
        log.info("select * from ap_user where id%2=="+shardIndex);
    }


    @XxlJob("myjob-run1")
    public void run1(){
        //获取当前实例的索引
        int shardIndex = XxlJobHelper.getShardIndex();
        //获取所有实例的个数
        int shardTotal = XxlJobHelper.getShardTotal();

        log.info("当前实例的索引{},总实例的个数{}",shardIndex,shardTotal);
        log.info("select * from ap_user where id%2=="+shardIndex);
    }



}
